<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <span id="txt"></span>
    <input type="button" value="确定" id="btn">
</body>
<script>

    var num = 0;
    var txt;
    var btn;

    window.onload = function () {
        txt = document.getElementById('txt');
        btn = document.getElementById('btn');

        if(sessionStorage.num){
            num = sessionStorage.num;

        }else{
            num = 0;
        }

        btn.onclick = function () {
            num++;
            sessionStorage.num = num;
            showNum();
        }
    }
    function showNum() {
        txt.innerHTML  = num;
    }

</script>
</html>